package com.totoro.mysql;

import com.google.common.util.concurrent.SimpleTimeLimiter;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

public class MethodOutTime {
    public static void test() throws Exception {
        SimpleTimeLimiter st = new SimpleTimeLimiter() ;

        String r1 = st.callWithTimeout(new Callable<String>() {
            @Override
            public String call() throws Exception {
                return "Hello";
            }
        }, 10, TimeUnit.MILLISECONDS, true) ;

        System.out.println(r1);

        String r2 = st.callWithTimeout(new Callable<String>() {
            @Override
            public String call() throws Exception {
                Thread.sleep(1000);
                return "world";
            }
        }, 10, TimeUnit.MILLISECONDS, true) ;
        System.out.println(r2);
    }


    public static void main(String[] args) {
        try {
            test();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
